/*
 * LogonView.fx
 *
 * Created on 2010-03-10, 12:44:48
 */

package testlogowowanie;
import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.layout.VBox;
import javafx.scene.control.TextBox;
import java.lang.String;
import javafx.scene.control.Button;
import java.lang.UnsupportedOperationException;
import testlogowowanie.IAHelper;
import javafx.scene.text.Text;
import javafx.scene.text.Font;

/**
 * @author pgorzkowicz
 */

public class LogonView extends CustomNode, ILogon {
   var aHelper:IAHelper;
   
   
   override public function help (arg0 : IAHelper) : Void { 
        this.aHelper=arg0;
    }

    override public function getLogin () : String {
       return loginTBox.text;
    }

    override public function getPassword () : String {
        return passTBox.text;
    }

    var authStatus:String = "<...>";

    function checkAuthorisation(){
        def login = loginTBox.text;
        def password = passTBox.text;

        if(aHelper!=null){
            def isAuthorised = aHelper.checkAuth(login, password);
            if(isAuthorised){
                authStatus =  "authorised";
            }else{
                authStatus = "not authorised !!!";
            }
        }else{
            authStatus = "aHelper jest nullem";
        }

    }

    var loginTBox:TextBox = TextBox {
        text: "login"
	columns: 12
	selectOnFocus: true
    }

    var passTBox:TextBox = TextBox {
        text: "password"
	columns: 12
	selectOnFocus: true
    }

    def confirmButton:Button = Button {
	text: "Login"
	action: function() {
		checkAuthorisation();
	}
    }
    def statusLabel:Text = Text {
	font : Font {
		size: 24
	}
	content: bind authStatus;
}



    override protected function create () : Node {
        return VBox{
            spacing: 5;
            content: [loginTBox,passTBox,confirmButton,statusLabel];
        }
    }





}
